import { ipcMain } from 'electron';
import LocalConfig from "@main/common/localConfig"


class API {

    init() {
        ipcMain.on('msg-trigger', async (event, arg) => {
            // const window = arg.winId ? BrowserWindow.fromId(arg.winId) : mainWindow;
            let data: any
            if (arg.data) {
                data = await this[arg.type](arg.data);
            } else {
                data = await this[arg.type]();
            }
            event.returnValue = data;
            // event.sender.send(`msg-back-${arg.type}`, data);
          });
    }

    public getLocalConfig() {
        return LocalConfig.config_data;
    }

    public saveServerModel(data) {
        return LocalConfig.setConfig(data["key"], data["value"])
    }

    public saveSystemConfig(data) {
        return LocalConfig.saveSystemConfig(data)
    }

    public inItConfig(){
        LocalConfig.initConfig()
    }
}

export default new API()
